<template>
  <div class="similar-content-info tag-scrollbar">
    <div class="section-title"><icon-svg name="iconSystem"></icon-svg>种子人群配置</div>
    <div class="section-content">
      <tag-devired-logic :derivedTag="sourceLogic"></tag-devired-logic>
    </div>
    <div class="section-title"><icon-svg name="iconSystem"></icon-svg>目标人群配置</div>
    <div class="section-content">
      <tag-devired-logic :derivedTag="targetLogic"></tag-devired-logic>
    </div>
    <div class="story-box">
      <div class="story-title linear-blue">
        <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
        结果预览
      </div>
      <div class="story-content ">
        <div class="result-title">
          <el-row>
            <el-col :span="8" align="center"><span>种子人群命中客户数（人）</span></el-col>
            <el-col :span="8" align="center"><span>目标人群命中客户数（人）</span></el-col>
            <el-col :span="8" align="center"><span>种子人群抽样比例</span></el-col>
          </el-row>
        </div>
        <div class="result-content">
          <el-row>
            <el-col :span="8" align="center">
              <div class="cust-statistic">
                <el-row :gutter="20">
                  <el-col :span="12" align="center">
                    <tag-progress
                      type="circle"
                      :percentage="config.sourceCustRate"
                      :behindStrokeWidth="5"
                      :gapWidth="2"
                      stroke-linecap="square"
                      color="#007aff"
                      bebindColor="#e9f0f7"
                      class="quality-progress"
                      :width="100"
                    >
                      <div slot="content" class="quality-inner-text">
                        <p>{{ config.sourceCustRate }}%</p>
                      </div>
                    </tag-progress>
                  </el-col>
                  <el-col :span="12" align="center">
                    <span class="count">{{ config.sourceCustNum }}</span>
                    <br />
                    在全部用户中占比{{ config.sourceCustRate }}%
                  </el-col>
                </el-row>
              </div>
            </el-col>
            <el-col :span="8" align="center">
              <div class="cust-statistic">
                <el-row :gutter="20">
                  <el-col :span="12" align="center">
                    <tag-progress
                      type="circle"
                      :percentage="config.targetCustRate"
                      :behindStrokeWidth="5"
                      :gapWidth="2"
                      stroke-linecap="square"
                      color="#007aff"
                      bebindColor="#e9f0f7"
                      class="quality-progress"
                      :width="100"
                    >
                      <div slot="content" class="quality-inner-text">
                        <p>{{ config.targetCustRate }}%</p>
                      </div>
                    </tag-progress>
                  </el-col>
                  <el-col :span="12" align="center">
                    <span class="count">{{ config.targetCustNum }}</span>
                    <br />
                    在全部用户中占比{{ config.targetCustRate }}%
                  </el-col>
                </el-row>
              </div>
            </el-col>
            <el-col :span="8" align="center">
              <div class="result-info-line">{{ config.sampleRate }}</div>
            </el-col>
          </el-row>
        </div>
        <div class="result-title">
          <el-row>
            <el-col :span="4" align="center"><span>更新周期</span></el-col>
            <el-col :span="5" align="center"><span>运行结果</span></el-col>
            <el-col :span="5" align="center"><span>上次运行时间</span></el-col>
            <el-col :span="10">
              <el-row>
                <el-col :span="12" align="center"><span>用户标识</span></el-col>
                <el-col :span="12" align="center"><span>相似度预览</span></el-col>
              </el-row>
            </el-col>
          </el-row>
        </div>
        <div class="result-content result-cust">
          <el-row>
            <el-col :span="4" align="center">
              <div class="result-info-line">{{ $dict('$exec_frequency')[config.execFrequency] }}</div>
            </el-col>
            <el-col :span="5" align="center">
              <div
                class="result-info-line"
                :class="{
                  'result-running': config.tagReqStatus === 1,
                  'result-error': config.tagReqStatus === 2 || config.tagReqStatus === 4
                }"
              >
                {{ config.tagReqStatus | resultFormatter }}
              </div>
            </el-col>
            <el-col :span="5" align="center">
              <div class="result-info-line">{{ config.startTime }}</div>
            </el-col>
            <el-col :span="10" align="center">
              <ul class="tag-scrollbar" v-if="config.tagReqStatus === 3">
                <li v-for="(item, index) in showResult" :key="index">
                  <el-col :span="12">{{ index + 1 }}</el-col>
                  <el-col :span="12">{{ item }}</el-col>
                </li>
              </ul>
              <div class="result-info-line result-error" v-else>
                <span v-if="config.tagReqStatus === 2 || config.tagReqStatus === 4">{{ config.tagReqMsg }}</span>
                <span v-else>暂无</span>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
    <div class="story-box short">
      <div class="story-title linear-orange">
        <span class="icon"><icon-svg name="iconCalculateTag"></icon-svg></span><br />
        备注
      </div>
      <div class="story-content story-text">
        <el-input type="textarea" v-model="config.tagStory" :rows="8" resize="none" disabled></el-input>
      </div>
    </div>
  </div>
</template>

<script>
import similarLogic from '../similar-config.js'
export default {
  props: {
    config: {
      type: Object,
      required: true,
      default: () => {}
    }
  },
  computed: {
    sourceLogic() {
      const logic = JSON.parse(this.config.tagSourceJson)
      let derivedTag = {
        logicalOperation: logic.request.labGrps.logicTyp,
        tagList: similarLogic.initLogic(
          logic.request.labGrps.labs ? logic.request.labGrps.labs : [],
          this.config.baseTags
        )
      }
      return derivedTag
    },
    targetLogic() {
      const logic = JSON.parse(this.config.tagTargetJson)
      let derivedTag = {
        logicalOperation: logic.request.labGrps.logicTyp,
        tagList: similarLogic.initLogic(
          logic.request.labGrps.labs ? logic.request.labGrps.labs : [],
          this.config.baseTags
        )
      }
      return derivedTag
    },
    showResult() {
      return JSON.parse(this.config.previewResults)
    }
  },
  filters: {
    resultFormatter(val) {
      let text = '运行成功'
      switch (val) {
        case 1:
          text = '运行中'
          break
        case 2:
          text = '请求失败'
          break
        case 3:
          text = '执行成功'
          break
        case 4:
          text = '执行失败'
          break
        default:
          text = '运行成功'
          break
      }
      return text
    }
  },
  data() {
    return {}
  },
  methods: {}
}
</script>

<style lang="scss">
.tag-similar {
  .similar-content-info {
    height: calc(100% - 60px);
    overflow-y: auto;
    .section-title {
      font-size: 18px;
      font-weight: bold;
      height: 80px;
      padding: 20px;
      line-height: 40px;
      color: #1e3592;
      background-color: #c0d2f6;
      border-top-left-radius: 5px;
      border-top-right-radius: 5px;
      svg {
        width: 22px;
        height: 22px;
        margin: -5px 10px 0 0;
        vertical-align: middle;
      }
    }
    .section-content {
      background-color: #f6f7f8;
      margin: -5px 0 10px 0;
      padding: 10px 0;
      .no-record {
        padding-top: 10px;
      }
    }
    .el-col {
      word-break: break-all;
    }
    .result-info-line {
      font-size: 20px;
      font-weight: bold;
      height: 140px;
      line-height: 30px;
      padding-top: 50px;
      color: $tag-green;
    }
    .result-running {
      color: #4d82e9;
    }
    .result-error {
      color: $tag-red;
    }
    .story-box {
      margin-top: 10px;
      height: 460px;
      border-radius: 5px;
      box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
      overflow: hidden;
      position: relative;
      &.short {
        height: 180px;
        .icon {
          margin-top: 40px;
        }
      }
    }
    .story-title {
      font-size: 17px;
      font-weight: bold;
      width: 200px;
      height: 100%;
      color: #fff;
      text-align: center;
      position: relative;
      &:before {
        width: 100%;
        height: 100%;
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        background: url(~@/assets/img/params_bg.png) no-repeat 0px 0px/100% 100%;
      }
    }
    .icon {
      display: inline-block;
      width: 80px;
      height: 80px;
      background-color: #fff;
      margin: 170px 0 10px;
      border-radius: 50%;
      svg {
        width: 50px;
        height: 50px;
        margin-top: 15px;
      }
    }
    .linear-orange {
      background: linear-gradient(to bottom, #f3bf7c, #f3b172);
      svg {
        color: #f3b172;
      }
    }
    .linear-blue {
      background: linear-gradient(to bottom, #63a3fc, #5188ec);
      svg {
        color: #5188ec;
      }
    }
    .story-content {
      padding-left: 200px;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
    }
    .result-title {
      font-weight: bold;
      height: 60px;
      border-bottom: 1px solid #eee;
      span {
        display: inline-block;
        width: 80%;
        height: 40px;
        line-height: 40px;
        margin: 10px 0 10px 0;
        background-color: #fcf5e5;
        border-radius: 20px;
      }
    }
    .el-textarea.is-disabled .el-textarea__inner {
      color: #333;
      cursor: default;
    }
    .result-content {
      height: 140px;
      .el-row,
      .el-col-8 {
        height: 100%;
      }
      ul {
        height: 100%;
        overflow-y: auto;
        li {
          height: 40px;
          line-height: 40px;
          text-align: center;
          .el-col {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }
      }
      & + .result-title {
        border-top: 1px solid #eee;
      }
    }
    .result-cust {
      height: 200px;
      .result-info-line {
        padding-top: 70px;
      }
    }
    .cust-statistic {
      padding: 20px 5% 0 5%;
    }
    .count {
      display: inline-block;
      font-size: 25px;
      font-weight: bold;
      color: #f4942b;
      margin: 20px 0;
    }
  }
  .el-col-10 {
    height: 100%;
  }
}
</style>
